package com.cyj.springbootservice.controller.zxing;

import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.cyj.springbootservice.utils.ImageUtils;

import java.awt.image.BufferedImage;

/**
 * @description: 生成二维码
 * @Author C_Y_J
 * @create 2021/10/26 14:34
 **/
public class CreateQRCode {

    public static void main(String[] args) {
//        // 生成指定url对应的二维码到文件，宽和高都是300像素
//        QrCodeUtil.generate("deptId:159753", 300, 300, FileUtil.file("d:/qrcode1.jpg"));
//
//
//
//        QrConfig config = new QrConfig(300, 300);
//        // 设置边距，既二维码和背景之间的边距
//        config.setMargin(3);
//        // 设置前景色，既二维码颜色（青色）
//        config.setForeColor(Color.CYAN.getRGB());
//        // 设置背景色（灰色）
//        config.setBackColor(Color.GRAY.getRGB());
//        // 生成二维码到文件，也可以到流
//        QrCodeUtil.generate("deptId:159753", config, FileUtil.file("d:/qrcode2.jpg"));


        /**
         * 附带logo小图标
         */
        BufferedImage base64StrToImage = ImageUtils.getBase64StrToImage("iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAABr1JREFUeF7tW3lsFUUY/80rpSqH0oiKIrZopJXLiqB4YxRFRJseENGoxAPEUDUxWJX4ByoqJCoYEVADRsGjRziUqjGkIGDkagvhKBpai4ABJC3laAu88fvedrrz9h07JZXC2/f9077dme/4fdfszqzAaVJGruzu92MYBIYIiavpb4oAUondhafJ0nRanQSqaHAV/d0FiXUnffhla4E4ZMpAH0c6m1N6luyR5MMkmvQgzepvPvMMjJTYRE5Y3uDH7O3FYp+pRCMAmg2fTIPHE+PzTZm307jjUmJOo8QMEyCiAnCOGe7EOwBEQhOmbVwmDkZyRkQABg2Sif4UzKKwmtBOnmwbsQSCrxp5GzeKE+EYhgWgb65MTvRjmRC4pW20aF8uFAlrT/gwKlyhDAXgLtkh42KsIpWHtq/abSudOsbq8oPUtUrFyahdICNHzqEBXOxikeaWFYqglA6KgIxsOYFy/pNYtLz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Tp0PWCwBXe6bfN4f2YF4xKu9zJOzabRugeOsLHr2LhDNI7yz6oovHMvDhVqROPq4A6OGrT2bEo1H5DgsgRfo6gI1d+D1tQY+2ooc7xtzvgFHD7Ogw8ajeWVQLVvKUQ9wiISoAjGLOcNvDf+2xWqAJ6QA4o2hpKTD2gWDjh98aWhvcenkk57B+zoiIpLNrBJgY6zaG64ii9bSQSqPDdLxWZ+L1+g469DZYW06brOF5rs7XqYNJC+U5ZwQAN4Da834cgPg7wfg7QUkd/X8/39ueaR5Ndh3vDXrubIBChM8IxDdHPb897vkDEp4/IsMFwYuFsOWQVACAbPkhnRGgh1kPkR/vlRWLfOuYXKZMER0CJ8Vi/Zis8nADnYrpVVYgDrScFc7Iku/Ch1c8EQPN3g88DSqDrxkhu3bphBoPrAoPH2tCz8qlIrAv5Twu/whdWRTLUeCXGFNRJOj9k0UhX4zEdCpooR8RAEDS0TmUEjR3xFgklJQVYiT5POg8RNiPpvirUDpGuoEA6BUTIEjsrj+Gfn+WiMNOe2L+szly92cJVZjYqs/mdJQG5sjxPtqBomvn2scUp+DHeFrsfB4tio0+naUvSvr4JF4mRo/TBNocP6vpBKXvl6d8mL65QNDeU3QyAkCxGJAle/oE8mnZ/NTZtmqkUD9Khs+jNvf+5mLxt5vhUbqA2VQqlEPpgN1oEjqEUOxGXaMbzbzoDADTQDJqSW4tGc2fzK+RPhRWFAjatWw9/Qd7pZVl3aKB3AAAAABJRU5ErkJggg==");
        BufferedImage generate = QrCodeUtil.generate(
                "蔡浩家是大帅哥",
                QrConfig.create().setImg(base64StrToImage)

        );

        System.out.println(ImageUtils.getImageToBase64Str(generate));


//        /**
//         * 调整纠错级别
//         */
//        QrConfig config2 = new QrConfig();
//        // 高纠错级别
//        config2.setErrorCorrection(ErrorCorrectionLevel.H);
//        QrCodeUtil.generate("deptId:159753", config2, FileUtil.file("d:/qrcode4.jpg"));
    }
}
